<!DOCTYPE html>
<html>

<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <title>授权书</title>
    <meta name="viewport" content="initial-scale=1, maximum-scale=1">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm.min.css">
    <link rel="stylesheet" href="/static/wx/lib/sui/sm-extend.min.css">
    <link rel="stylesheet" href="/static/wx/css/reset.css">
    <link rel="stylesheet" href="/static/wx/css/main.css">
    <link rel="stylesheet" href="/static/wx/css/public_main.css">
</head>

<body>
    <div class="page-group">
        <div class="page page-current" id="upload_authBook">
            <!-- 主内容 -->
            <div class="content">
                <div class="auth-book">
                    <img src="/static/wx/imgs/img/auth_book.png">
                </div>
                <p class="text-c size-65 mark">此授权书为格式文档，点击右上角分享打印盖章后上传</p>
                <div class="bs-box">
                    <div class="bs-box-content">
                        <div class="bs-box-inner">
                            <div class="bs-box-content-item border-b-none">
                                <p class="size-m">上传授权书</p>
                                <div class="uploader">
                                    <ul class="uploader-files" id="uploader-files">
                                    </ul>
                                    <div class="uploader-content">
                                        <div class="uploader-input-box">
                                            <div class="uploader-input-box"><input type="file" accept="image/*" class="uploader-input" onchange="handleInputChange1(event)"></div>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
                <input type="hidden" value="{$Think.get.policy_num}" name='policy_num'/>
                <div class="btn-box">
                    <div class="my-btn size-m" id="nextStep">
                        <span class="active">上传授权书并提交</span>
                    </div>
                </div>
            </div>

        </div>
    </div>
    <script type='text/javascript' src='/static/wx/lib/sui/zepto.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/lib/sui/sm.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/lib/sui/sm-extend.min.js' charset='utf-8'></script>
    <script type='text/javascript' src='/static/wx/js/upload.js' charset='utf-8'></script>
</body>
<script>
    $(function () {
        var n = $('.step-box').children().length;
        $('.step-item').css('width', document.body.clientWidth / n + 'px')
        $(document).on('click', '#nextStep', function () {
            var poliecy = $("input[ name='policy_num']").val();
            var arr='';
            var  obj=$("#uploader-files  li");
            if(obj.length>1){
                $.alert('只能上传一张授权书');
                return;
            }
            if(obj.length ==1){
                $("#uploader-files  li").each(function(index){
                    var url=$(this).css('background-image');
                    arr= url.split('("')[1].split('")')[0];
                })
            }
            $.ajax({
                type: 'POST',
                url: "{:url('insurer/confirmSubmit')}",
                data: {
                    'policy_num': poliecy,
                    'author_report':arr
                },
                dataType: 'json',
                success: function (Json) {
                    console.log(Json);
                    if (Json.code == 200) {
                        $.alert('提交审核成功');
                        location.href = "{:url('insurer/getList')}";
                    } else {
                        $.alert(Json.msg);
                    }
                }
            });
        });
    });
    //获取对象
    function handleInputChange1(event) {
        //   console.log(event)
        var formData= handleInputChange(event);
        console.log(formData);
        uploadImg(formData);

    }
    // 上传图片
    function  uploadImg (formData) {
        $.ajax({
            type: 'POST',
            url: "{:url('upload/index')}",
            data: formData,
            processData: false,
            contentType: false,
            cache: false,
            success: function (Json) {
                if (Json.code == 200) {
                    var url=decodeURI(Json.data.url)
                    var obj=url.lastIndexOf("/");
                    var name =url.substr(obj+1);
                    a="<li class=\"uploader-file\" style=\"background-image:url('"+url+"')\">";
                    a+= "<span class=\"close\" onclick='deleteT(this) '>x</span>"
                    a+= "</li>"
                    a+= "</li>"
                    $('#uploader-files').append(a);
                } else {
                    $.alert('上传失败');
                }
            }
        });
    }
    function deleteT(obj) {
        $(obj).parent('li').remove();

    }

</script>

</html>